

OUT_PATH = .
BUILD_PATH = .
SPROTO_PATH = sproto

CC = gcc -std=gnu99
PLAT ?= mingw

# lua
LUA_PATH := $(BUILD_PATH)/lua53
LUA_INC := $(LUA_PATH)
LUA_STATICLIB := $(LUA_PATH)/liblua.a

CFLAGS := -g -O2 -Wall -I$(LUA_INC) $(MYCFLAGS)

# link
SHARED := --shared
SHAREDLDFLAGS := -llua53 -L$(BUILD_PATH)

all : \
	$(LUA_STATICLIB) \
	$(OUT_PATH)/sproto.so \
	clean
	
# lua
$(LUA_STATICLIB) :
	cd $(LUA_PATH) && $(MAKE) CC='$(CC)' $(PLAT)  && cd - && cp -f $(LUA_PATH)/lua53.dll $(OUT_PATH)/lua53.dll


# sproto
$(OUT_PATH)/sproto.so : $(SPROTO_PATH)/sproto.c $(SPROTO_PATH)/lsproto.c | $(OUT_PATH)
	$(CC) $(CFLAGS) $(SHARED) -I$(SPROTO_PATH) $^ -o $@  $(SHAREDLDFLAGS) 

	
clean :
	# rm -f $(OUT_PATH)/*.so $(OUT_PATH)/*.dll
	cd $(LUA_PATH) && $(MAKE) clean && rm -f $(LUA_STATICLIB) *.exe *.dll

